/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx.mapper;

import cn.webrx.entity.Roles;
import cn.webrx.entity.Users;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * <p>Project: mybatis2022 - RolesMapper
 * <p>Powered by webrx On 2022-04-15 09:16:10
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@Mapper
public interface RolesMapper {
    @Select("select * from w_roles where name = #{name}")
    @Results(id="rm",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "name",column = "name"),
            @Result(property = "users",column = "id",many = @Many(select = "suser",fetchType = FetchType.EAGER))
    })
    public Roles queryByName(String n);

    @Select("select wr.name from w_users_roles wu join w_users wr on wu.role_id = ${id} and wr.id = wu.user_id")
    public List<String> suser();

    @Select("select * from w_roles") @ResultMap("rm")
    public List<Roles> queryAll();
}
